﻿import QtQuick 2.0
import "../../js/UI.js" as Style
import "../common"
import "../../js/util.js" as Util
Rectangle {
    id: messageBoxBackground
    property string m_title:"提示"
    property string m_prompt:""
    property int fontSize : 0.03 * parent.height
    signal itemClicked(int index)
    signal closeSignal

    function doModal(title,prompt)
    {
        m_title = title;
        m_prompt = prompt;
        messageBoxBackground.state = "visible";
        Qt.inputMethod.hide();
    }

    function hide() {
        messageBoxBackground.state = "";
    }

    function getVisbleState() {
        return (messageBoxBackground.state == "visible")
    }

    visible: false
    anchors.fill: parent
    color: Util.isMobileDevice() ? "#80000000" : "#10000000"
    //点击对话框区域外，隐藏对话框，其父窗口最后变为最外层窗口，在Component.onCompleted事件中设置
    MouseArea {
        anchors.fill: parent//
        onClicked:
        {

        }
    }

    // 对话框
    Rectangle {
        id: messageBox
        color: "white"
        width: Util.isMobileDevice()? 0.8 * parent.width : 0.3*parent.width
        height: 0.3 * parent.height
        radius: m_lineValue*0.1
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter

        Column
        {
            anchors.fill: parent
            Rectangle
            {
                width: parent.width
                height:0.25 * parent.height
                color: "transparent"
                AText
                {
                    anchors.centerIn: parent
                    font.pointSize: Util.isMobileDevice()?20:Util.isHDScreen()?14:14
                    color: Style.titlePontColor
                    text:m_title
                }
            }


            SplitLine{
                width: parent.width-m_lineValue*0.4
                anchors.horizontalCenter: parent.horizontalCenter
            }

            AText
            {
                id:textText
                width: parent.width
                height:0.5 * parent.height
                horizontalAlignment:Text.AlignHCenter
                verticalAlignment:Text.AlignVCenter
                font.pointSize: Util.isMobileDevice()?20:Util.isHDScreen()?14:14
                wrapMode:Text.WordWrap
                text:m_prompt
                color: Style.titlePontColor
            }

            SplitLine{
                width: parent.width-m_lineValue*0.4
                anchors.horizontalCenter: parent.horizontalCenter
            }

            Rectangle
            {
                width: parent.width
                height:0.25 * parent.height
                radius: m_lineValue*0.1
                AText
                {
                    anchors.fill: parent
                    horizontalAlignment:Text.AlignHCenter
                    verticalAlignment:Text.AlignVCenter
                    font.pointSize: Util.isMobileDevice()?20:Util.isHDScreen()?14:14
                    text:"确定"
                    color: Style.TitletextColor
                }
                MouseArea {
                    id: mouseid
                    anchors.fill: parent//
                    onClicked:
                    {
                        messageBoxBackground.state = "";
                        closeSignal()
                    }
                }               
                color: mouseid.pressed?Style.mousePressedColor:"transparent"
            }
        }
    }

    states: State {
        name: "visible"
        PropertyChanges {target: messageBoxBackground; visible: true}
    }
    transitions: Transition {
        NumberAnimation {
            target:  messageBoxBackground
            properties: "visible"
            duration: 250
        }
    }
    Component.onCompleted:
    {
//        var docRoot = messageBoxBackground.parent;
//        while(docRoot.parent)
//        {
//            docRoot = docRoot.parent;
//        }
//        messageBoxBackground.parent = docRoot;
    }
//    function isMobileDevice() {
//        return (Qt.platform.os == "android" || Qt.platform.os == "ios");
//    }
}

